/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.service;

import com.dao.GeneratorDao;
import com.pojo.CodeFile;
import com.pojo.ColumnInfo;
import com.pojo.TableInfo;
import com.util.GenUtil;

import java.util.ArrayList;
import java.util.List;


public class GeneratorService {
    private GeneratorDao generatorDao = new GeneratorDao();

    public List<TableInfo> getTables() {
        return generatorDao.getTables();
    }

    public TableInfo getTableInfo(String tableName) {
        return generatorDao.getTableInfo(tableName);
    }

    public List<ColumnInfo> getColumnsOfTable(String tableName) {
        return generatorDao.getColumnsOfTable(tableName);
    }

    public List<CodeFile> generateCode(String tableName) {
        TableInfo tableInfo = getTableInfo(tableName); // 查询表信息
        List<ColumnInfo> columns = getColumnsOfTable(tableName); // 查询列信息
        if (tableInfo == null)
            return new ArrayList<>(0);
        return GenUtil.generateCode(tableInfo, columns); // 生成代码
    }

    public static void main(String[] args) {
        List<CodeFile> list = new GeneratorService().generateCode("user");
        System.out.println(list);
    }
}
